#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 5e5 + 10;
int tre[N][26];
int e[N];
int idx;
void insert(string& s)
{
    int cnt = 0;
    for (auto e : s)
    {
        int path = e - 'a';
        if (tre[cnt][path] == 0)
        {
            tre[cnt][path] = ++idx;
        }
        cnt = tre[cnt][path];
    }
    e[cnt]++;
}
int find(string& s)
{
    int cnt = 0;
    for (auto e : s)
    {
        int path = e - 'a';
        if (tre[cnt][path] == 0)
        {
            return 0;
        }
        cnt = tre[cnt][path];
    }
    if (e[cnt] > 0)
    {
        int t = e[cnt];
        e[cnt] = -1;
        return t;
    }

    return e[cnt];
}
int main()
{
    int n, m;
    cin >> n;
    while (n--)
    {
        string s;
        cin >> s;
        insert(s);
    }
    cin >> m;
    while (m--)
    {
        string t;
        cin >> t;
        int ret = find(t);
        if (ret == 0)
        {
            cout << "WRONG" << endl;
        }
        else if (ret > 0)
        {
            cout << "OK" << endl;
        }
        else
        {
            cout << "REPEAT" << endl;
        }
    }
    return 0;
}